<?php

namespace App\Http\Controllers\Admin;

use App\Models\Onorder;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class OnpackorderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function __construct()
    {
        view()->share([
            '_orders' => 'am-in',
            '_onpack' => 'am-active',
        ]);
    }
//挑战管理
    public function index(Request $request)
    {
        $where = function ($query) use ($request) {
            if($request->has('order_no')and $request->order_no !=''){
                $search = "%".$request->order_no."%";
                $query->where('order_no','like',$search);
            }
            if($request->has('statu')and $request->statu !='-1'){
                $query->where('statu',$request->statu);
            }
            if($request->has('created_at')and $request->created_at !=""){
                $time = explode(" ~ ",$request->created_at);
                $start = $time[0] . ' 00:00:00';
                $end = $time[1] . ' 23:59:59';
                $query->whereBetween('created_at',[$start,$end]);
            }
        };
        $orders=Onorder::where('type',0)->where('is_pay',1)->where($where)->with('fixfxs')->with('oncustomer')->with('pack')->with('item')->
        orderBy('pay_at','desc')->paginate(20);

//return $orders;die;
       return view('admin.order.onpackorder',compact('orders'));
    }


    public function change_attr(Request $request)
    {

        $order = Onorder::find($request->id);

        if ($order->statu == 0) {
            $data['statu'] = 1;
            $order->update($data);
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
